/**
 * Copyright (C) 2007, geolabs
 * Copyright (C) 2007, Gérald Fenoy djay@cartography.st
 */

/**
 * Toys Class
 * This static class is used to define all toys available in the framework, ie
 * we have a div which follow mouse and as we conciderate this as a toy then we
 * putting there ;)
 */
System.require("Position");
System.require("Styler");

Toys=Class.create({
    /**
     * divRelatifveToAnElement
     * display an information div for a specified dom element
     * @params el the dom element (must have a valid identifier)
     * @params content the content of the info div
     * @params position of the ino div
     */
  divRelativeToAnElement: function(el,content,pos){
      var initialPos=Position.fromElement(el);
      /* create the info div */
      var infoDiv=document.createElement('dvi');
      infoDiv.setAttribute("class","info");
      infoDiv.setAttribute("id",el.id+"_info");
      infoDiv.innerHTML=content;
      el.parentNode.appendChild(infoDiv);
      Styler.setStyle(infoDiv,"display: none;");
      Position.ensurePositioned(infoDiv,initialPos);

      /* Setup the relative position with relatively to the pos value */
      var relativePos=initialPos;

      /* Setup event */
      el.onmouseover=new Function("document.getElementById('"+el.id+"').style.display=block;Position.ensurePositioned(document.getElementById('"+el.id+"'),new Position("+relativePos.x+","+relativePos.y+"));");
      el.onmouseout=new Function("document.getElementById('"+el.id+"').style.display=none;");

    }
  });
